<template>
  <div id="form-list" v-loading="treeLoading">
    <el-input
      type="text"
      placeholder="请输入搜索内容"
      v-model="searchText"
      @input="filter"
    >
      <i slot="prefix" class="el-input__icon el-icon-search"></i>
    </el-input>
    <!-- tree -->
    <el-tree
      :data="treeList"
      :props="defaultProps"
      @node-click="onActiveClick"
      highlight-current
      :filter-node-method="filterNode"
      ref="tree"
    >
    </el-tree>
  </div>
</template>
<script>
export default {
  name: "formList",
  data() {
    return {
      searchText: "",
      treeLoading: true,
      treeList: [],
      defaultProps: {
        children: "children",
        label: "tableName",
      },
    };
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.tableName.indexOf(value) !== -1;
    },
    filter(val) {
      this.$refs.tree.filter(val);
    },
    //选中某节点
    onActiveClick(data) {
      this.$emit("nodeClick", data);
    },
    //初始化获取数据
    async getTableList() {
      const res = await this.$http({
        data: {},
        url: "form/table-template/getTableList",
      });
      this.treeLoading = false;
      this.treeList = res;
    },
  },
  created() {
    this.getTableList();
  },
};
</script>
